package org.come.control;

import com.tool.role.RoleData;
import org.come.Frame.GetLiangHaoJframe;
import org.come.Frame.TaobaoCourtMainJframe;
import org.come.Frame.Teststatejframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.GetLiangHaoJpanel;
import org.come.action.FromServerAction;
import org.come.bean.MyLiangHaoAucBean;
import org.come.bean.SearchSellLiangHaoResultBean;
import org.come.entity.SellLiangHaoBase;
import org.come.entity.SellLianghaoAuc;
import org.come.until.GsonUtil;

import java.util.List;

public class SellLiangHaoControl implements FromServerAction {
    public void controlMessFromServer(String mes, String type) {
        GetLiangHaoJpanel getLiangHaoJpanel = TaobaoCourtMainJframe.getTaobaoCourtJframe().getTaobaoCourtMainJpanel().getTaobaoCourtCardJpanel().getGetLiangHaoJpanel();
        if (mes.startsWith("SELLLIST")) {
            String[] result = mes.split("\\|");
            if (result[1] != null) {
                SearchSellLiangHaoResultBean sa = GsonUtil.getGsonUtil().getgson().fromJson(result[1], SearchSellLiangHaoResultBean.class);
                GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoOneJpanel().setSlb(sa);
                getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoOneJpanel().setSlb(sa);
                if(sa.getXjDate()!=null){
                    GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoThreeJpanel().setXjDate(sa.getXjDate());
                    getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoThreeJpanel().setXjDate(sa.getXjDate());
                }
            }
        } else if (mes.startsWith("AUCLIST")) {
            String[] result = mes.split("\\|");
            if (result[1] != null) {
                SearchSellLiangHaoResultBean sa = GsonUtil.getGsonUtil().getgson().fromJson(result[1], SearchSellLiangHaoResultBean.class);
                GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().setAlb(sa);
                getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().setAlb(sa);
                if(sa.getXjDate()!=null){
                    GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoThreeJpanel().setXjDate(sa.getXjDate());
                    getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoThreeJpanel().setXjDate(sa.getXjDate());
                }
            }
        } else if (mes.startsWith("MYAUCLIST")) {
            String[] result = mes.split("\\|");
            if (result[1] != null) {
                MyLiangHaoAucBean sa = GsonUtil.getGsonUtil().getgson().fromJson(result[1], MyLiangHaoAucBean.class);
                GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().setMyLiangHaoAucBean(sa);
                getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().setMyLiangHaoAucBean(sa);
            }
        }else if(mes.startsWith("DROPLIANGHAO")){
            String[] result = mes.split("\\|");
            if (result.length>1) {
                RoleData.getRoleData().getLoginResult().setLianghaoexpire(null);
                RoleData.getRoleData().getLoginResult().setLiangHao(null);
                RoleData.getRoleData().getLoginResult().setLianghaotype(null);
                RoleData.getRoleData().getLoginResult().setContinueprice(null);

                ZhuFrame.getZhuJpanel().addPrompt2("你捐赠了靓号："+result[1]);

                Teststatejframe.getTeststatejframe().getTeststateJpanel().getLabappeleid().setText(String.valueOf(RoleData.getRoleData().getLoginResult().getRole_id()));
            }
        }else if(mes.startsWith("ADDLHTIME")){
            String[] result = mes.split("\\|");
            if (result.length>1) {
                RoleData.getRoleData().getLoginResult().setLianghaoexpire(result[1]);
            }
        }else if(mes.startsWith("CHANGETYPE")){
            String[] result = mes.split("\\|");
            if (result.length>1) {
                RoleData.getRoleData().getLoginResult().setLianghaotype(Integer.valueOf(result[1]));
            }
        }else if(mes.startsWith("EXPLIANGHAO")){
            String[] result = mes.split("\\|");
            if (result.length>1) {
                RoleData.getRoleData().getLoginResult().setLianghaoexpire(null);
                RoleData.getRoleData().getLoginResult().setLiangHao(null);
                RoleData.getRoleData().getLoginResult().setLianghaotype(null);
                RoleData.getRoleData().getLoginResult().setContinueprice(null);
                ZhuFrame.getZhuJpanel().addPrompt2("你的靓号"+result[1]+"已过期");
            }
        }else if(mes.startsWith("DELAUC")){
            String[] result = mes.split("\\|");
            if (result.length>1) {
                SellLianghaoAuc sellLianghaoAuc = GsonUtil.getGsonUtil().getgson().fromJson(result[1], SellLianghaoAuc.class);
                List<SellLianghaoAuc> slhs =  GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getMyLiangHaoAucBean().getSellLianghaoAucs();
                slhs = getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getMyLiangHaoAucBean().getSellLianghaoAucs();
                if(slhs!=null && slhs.size()>0){
                    for(SellLianghaoAuc item:slhs){
                        if(item.getId().equals(sellLianghaoAuc.getId())){
                            item.setStatus(sellLianghaoAuc.getStatus());
                        }
                    }
                }

                List<SellLiangHaoBase> lhlist =  GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getnLhList();
                lhlist = getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getnLhList();
                if(lhlist!=null && lhlist.size()>0){
                    for(SellLiangHaoBase item:lhlist){
                        if(item.getLianghao().equals(sellLianghaoAuc.getLianghao()) && (item.getAucPrice() == sellLianghaoAuc.getAucPoint().intValue())){
                            item.setAucPrice(0);
                        }
                    }
                }
            }
        }else if(mes.startsWith("BUYLIANGHAO")){
            String[] result = mes.split("\\|");
            if (result.length>1) {
                SellLiangHaoBase sellLiangHaoBase = GsonUtil.getGsonUtil().getgson().fromJson(result[1], SellLiangHaoBase.class);
                SearchSellLiangHaoResultBean ssb = GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoOneJpanel().getSlb();
                ssb = getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoOneJpanel().getSlb();
                if(ssb.getSellLiangHaos()!=null && ssb.getSellLiangHaos().size()>0){
                    for(SellLiangHaoBase item:ssb.getSellLiangHaos()){
                        if(sellLiangHaoBase.getLianghao().equals(item.getLianghao()) ){
                            ssb.getSellLiangHaos().remove(item);
                            return;
                        }
                    }
                };
            }
        }else if(mes.startsWith("BUYAUC")){     //竞价刷新数据
            String[] result = mes.split("\\|");
            if (result.length>1) {
                SellLianghaoAuc sellLianghaoAuc = GsonUtil.getGsonUtil().getgson().fromJson(result[1], SellLianghaoAuc.class);
                List<SellLiangHaoBase> lhlist =  GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getnLhList();
                List<SellLianghaoAuc> myaucs = GetLiangHaoJframe.getGetLiangHaoJframe().getGetLiangHaoJpanel().getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getMyLiangHaoAucBean().getSellLianghaoAucs();
                lhlist = getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getnLhList();
                myaucs = getLiangHaoJpanel.getGetliangHaoTabJpanel().getGetLiangHaoTwoJpanel().getMyLiangHaoAucBean().getSellLianghaoAucs();
                if(lhlist!=null && lhlist.size()>0){
                    for(SellLiangHaoBase item:lhlist){
                        if(item.getLianghao().equals(sellLianghaoAuc.getLianghao())){
                            item.setAucPrice(sellLianghaoAuc.getAucPoint().intValue());
                        }
                    }
                }
                if(myaucs!=null && myaucs.size()>0){
                    for(SellLianghaoAuc item:myaucs){
                        if(item.getLianghao().equals(sellLianghaoAuc.getLianghao())){
                            item.setAucPoint(sellLianghaoAuc.getAucPoint());
                            item.setOriginalprice(sellLianghaoAuc.getOriginalprice());
                            item.setStatus(sellLianghaoAuc.getStatus());
                            item.setBuyRoleId(sellLianghaoAuc.getBuyRoleId());
                            item.setAucEndTime(sellLianghaoAuc.getAucEndTime());
                            item.setId(sellLianghaoAuc.getId());
                        }
                    }
                }
            }
        }
    }
}
